package config

import (
	"flag"
	"os"
	"path"
	"sen-golang-study/go_game_study/hero_story_go_server/common/log"
)

type Config struct {
	ListenAddr    string
	EtcdEndpoints string
	LogPath       string
}

func NewConfig() *Config {
	listenAddr := flag.String("listen", "127.0.0.1:54321", "HTTP服务器监听地址")
	etcdEndpoints := flag.String("etcd", "127.0.0.1:2379", "etcd端点地址，多个地址用逗号分隔")
	flag.Parse()

	ex, err := os.Executable()
	if err != nil {
		panic(err)
	}

	logPath := path.Dir(ex) + "/log/gateway.log"
	log.Config(logPath)

	return &Config{
		ListenAddr:    *listenAddr,
		EtcdEndpoints: *etcdEndpoints,
		LogPath:       logPath,
	}
}
